﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="VIPList.aspx.cs" Inherits="VIP_VIPList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>VIP管理</title>
    <link href="../js/jquery-easyui-1.2.6/themes/default/easyui.css" rel="stylesheet"
        type="text/css" />
    <script src="../js/jquery-easyui-1.2.6/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../js/jquery-easyui-1.2.6/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../js/jquery-easyui-1.2.6/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <link href="../css/wms.css" rel="stylesheet" type="text/css" />
    <link href="../css/icon.css" rel="stylesheet" type="text/css" />
    <script src="../js/enter2tab.js" type="text/javascript"></script>
    <script type="text/javascript">
        var grd;
        var dlgEdit;
        var dlgEditForm;

        $(function () {
            grd = $('#viplist').datagrid({
                nowrap: true,
                striped: true,
                remoteSort: false,
                fitColumns: true,
                url: "VIP.ashx?action=list",
                frozenColumns: [[
                    { field: 'ck', checkbox: true }
                ]],
                columns: [[
                    { field: 'VipNo', title: 'VIP编号', width: 100 },
                    { field: 'VipName', title: '姓名', width: 100 },
                    { field: 'Cii', title: '店铺代码', width: 100 },
                    { field: 'VipZjno', title: '证件号码', width: 100 },
                    { field: 'VipDq', title: '发卡地区', width: 100 },
                    { field: 'VipDat', title: '发卡日期', width: 100 },
                    { field: 'VipJsrq', title: '有效日期', width: 100 },
                    { field: 'Operate', title: '操作', width: 70, align: 'center',
                        formatter: function (value, u, index) {
                            var e = '<a onclick="Edit(\'' + u.VipNo + '\');" title="编辑" iconcls="icon-edit-blue" class="easyui-linkbutton l-btn l-btn-plain" plain="true"><span class="l-btn-left"><span class="l-btn-text"><span class="l-btn-empty icon-edit-blue">&nbsp;</span></span></span></a>';
                            var d = '<a onclick="Delete(\'' + u.VipNo + '\')" title="删除" iconcls="icon-delete" class="easyui-linkbutton l-btn l-btn-plain" plain="true"><span class="l-btn-left"><span class="l-btn-text"><span class="l-btn-empty icon-delete">&nbsp;</span></span></span></a>';
                            return e + d;
                        }
                    }
                ]],
                pagination: true,
                rownumbers: true,
                toolbar:
                [
                    {
                        id: 'btnAdd',
                        text: '添加',
                        iconCls: 'icon-add-blue',
                        handler: Add
                    },
                    '-',
                    {
                        id: 'btnDelete',
                        text: '批量删除',
                        iconCls: 'icon-delete',
                        handler: function () {
                            var rows = $("#viplist").datagrid("getSelections");

                            if (rows.length == 0) {
                                $.messager.show({
                                    title: '操作提示',
                                    msg: '请选择您要删除的记录！',
                                    showType: 'slide',
                                    timeout: 3000
                                });
                            }
                            else {
                                $.messager.confirm("操作提示", "您确定要删除选中的记录吗？", function (data) {
                                    if (data) {
                                        var idlist = [];

                                        $.each(rows, function (i, row) {
                                            idlist.push(row.VipNo);
                                        });

                                        $.ajax({
                                            type: "POST",
                                            url: "VIP.ashx",
                                            data: "action=delete&VipNo=" + idlist.join(','),
                                            success: function (data) {
                                                eval('data=' + data);
                                                if (data.success) {
                                                    $.messager.alert('操作提示', '删除成功！', "info", function () {
                                                        $('#viplist').datagrid("reload");
                                                    });
                                                }
                                                else {
                                                    $.messager.alert('数据操作异常', data.message, "error");
                                                }
                                            },
                                            error: function () {
                                                $.messager.alert('异步操作异常', '异步操作错误！', "error");
                                            }
                                        });
                                    }
                                });
                            }
                        }
                    }
                ]
            });

            dlgEdit = $("#dlgEditVIP").dialog({
                closed: true,
                width: 750,
                height: 440,
                closable: true,
                draggable: true,
                resizable: false,
                modal: true,
                buttons:
                [
                    {
                        text: '保存',
                        iconCls: 'icon-ok',
                        handler: Save
                    },
				    {
				        text: '取消',
				        iconCls: 'icon-cancel',
				        handler: function () {
				            dlgEdit.dialog('close');
				        }
				    }
				],
                onClose: function () {
                    grd.datagrid('clearSelections');
                }
            });

            dlgEditForm = dlgEdit.find('form');
        });

        function prefix(i) {
            if (i < 10) {
                return "0" + i;
            } else {
                return i;
            }
        }
        // 添加
        function Add() {
            $("#VipNo").removeAttr("readonly").removeClass("readonly");
            dlgEdit.dialog('open');
            dlgEdit.form('clear');
            // 初始化发卡日期为当天日期
            var today = new Date();
            $("#VipDat").val(today.getFullYear() + '-' + prefix(today.getMonth() + 1) + '-' + prefix(today.getDate()));
            $("#VipNo").focus();
            $("#VipPro").val("110000"); //所属省份
            $("#VipSex").val("男"); //性别
            $("#VipHf").val("已婚"); //婚姻状况
            dlgEditForm.url = 'VIP.ashx?action=insert';
        }

        // 编辑
        function Edit(id) {
            // 编辑时VIP卡号不可修改
            $("#VipNo").attr("readonly", "readonly").addClass("readonly");
            dlgEdit.dialog('open');
            dlgEditForm.form('load', 'VIP.ashx?action=read&VipNo=' + id);
            dlgEditForm.url = 'VIP.ashx?action=update&VipNo=' + id;
        }

        // 删除
        function Delete(id) {
            $.messager.confirm("操作提示", "您确定要删除选中的记录吗？", function (data) {
                if (data) {
                    $.ajax({
                        type: "POST",
                        url: "VIP.ashx",
                        data: "action=delete&VipNo=" + id,
                        success: function (data) {
                            eval('data=' + data);
                            if (data.success) {
                                $.messager.alert('操作提示', '删除成功！', "info", function () {
                                    grd.datagrid("reload");
                                });
                            }
                            else {
                                $.messager.alert('数据操作异常', data.message, "error");
                            }
                        },
                        error: function () {
                            $.messager.alert('异步操作异常', '异步操作错误！', "error");
                        }
                    });
                }
                else {
                    grd.datagrid('clearSelections');
                }
            });
        }

        // 保存
        function Save() {
            if ($("#VipNo").val() == "") {
                $.messager.alert("操作提示", "VIP编号不能为空", "error");
                return;
            }
            if ($("#VipName").val() == "") {
                $.messager.alert("操作提示", "姓名不能为空", "error");
                return;
            }
            if ($("#VipZjlb").val() == "") {
                $.messager.alert("操作提示", "证件类别不能为空", "error");
                return;
            }
            if ($("#VipZjno").val() == "") {
                $.messager.alert("操作提示", "证件号码不能为空", "error");
                return;
            }
            if ($("#VipDat").val() == "") {
                $.messager.alert("操作提示", "发卡日期不能为空", "error");
                return;
            }
            if ($("#VipDq").val() == "") {
                $.messager.alert("操作提示", "发卡地区不能为空", "error");
                return;
            }
            if ($("#VipJsrq").val() == "") {
                $.messager.alert("操作提示", "有效日期不能为空", "error");
                return;
            }
            if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
                if (dlgEditForm.url == "VIP.ashx?action=insert") {
                    $.ajax({
                        type: "POST",
                        url: "VIP.ashx",
                        data: "action=exists&VipNo=" + $("#VipNo").val(),
                        success: function (oData) {
                            eval('oData=' + oData);
                            if (oData.success) {
                                $.messager.alert('操作提示', oData.message, "error");
                            }
                            else {
                                dlgEditForm.form('submit', {
                                    url: dlgEditForm.url,
                                    onSubmit: function () {
                                        return $(this).form('validate');
                                    },
                                    success: function (data) {
                                        dlgEdit.dialog('close');
                                        $.messager.alert('操作提示', '保存成功！', "info", function () {
                                            grd.datagrid("reload");
                                        });
                                    }
                                });
                            }
                        },
                        error: function () {
                            $.messager.alert('异步操作异常', '异步操作错误！', "error");
                        }
                    });
                } else {
                    dlgEditForm.form('submit', {
                        url: dlgEditForm.url,
                        onSubmit: function () {
                            return $(this).form('validate');
                        },
                        success: function (data) {
                            dlgEdit.dialog('close');
                            $.messager.alert('操作提示', '保存成功！', "info", function () {
                                grd.datagrid("reload");
                            });
                        }
                    });
                }
            } else {
                dlgEditForm.form('submit', {
                    url: dlgEditForm.url,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (data) {
                        eval('data=' + data);
                        if (data.success) {
                            $.messager.alert('操作提示', '保存成功！', "info", function () {
                                dlgEdit.dialog('close');
                                grd.datagrid("reload");
                            });
                        }
                        else {
                            $.messager.alert('操作提示', data.message, "error");
                        }
                    }
                });
            }
        }

        // 查询
        function Search() {
            grd.datagrid('options').url = 'VIP.ashx?action=list&VipNo=' + encodeURI($("#txtVipNo").val()) + '&VipName=' + encodeURI($("#txtVipName").val()) + '&VipZjno=' + encodeURI($("#txtVipZjno").val()) + '&VipDq=' + encodeURI($("#txtVipDq").val()) + '&StartVipDat=' + encodeURI($("#txtStartVipDat").val()) + '&EndVipDat=' + encodeURI($("#txtEndVipDat").val()) + '&StartVipJsrq=' + encodeURI($("#txtStartVipJsrq").val()) + '&EndVipJsrq=' + encodeURI($("#txtEndVipJsrq").val());
            grd.datagrid("reload");
        }

        // 清空
        function Reset() {
            $("#txtVipNo,#txtVipName,#txtVipZjno,#txtVipDq,#txtStartVipDat,#txtEndVipDat,#txtStartVipJsrq,#txtEndVipJsrq").val("");
            grd.datagrid('options').url = 'VIP.ashx?action=list';
            grd.datagrid("reload");
        }
    </script>
    <style type="text/css">
        .search-condition input
        {
            width: 100px;
        }
        .combo
        {
            border: none;
        }
    </style>
    <script src="../js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#txtStartVipDat,#txtEndVipDat,#txtStartVipJsrq,#txtEndVipJsrq,#VipTbjnr,#VipGlsr,#VipJsrq").bind("click", function () {
                WdatePicker()
            });
        });
    </script>
    <script type="text/javascript">
        $(function () {
            // 查询条件
            $("#search").bind("click", function () {
                Search();
            });
            // 清空
            $("#reset").bind("click", function () {
                Reset();
            });
        });
    </script>
    <script type="text/javascript">
        $(function () {
            // 初始化省份
            $.ajax({
                type: "get",
                dataType: "json",
                url: "../User/User.ashx?action=province",
                success: function (data) {
                    var VipPro = $("#VipPro");
                    $.each(data, function (index, item) {
                        VipPro.append("<option value='" + item.Id + "'>" + item.ProvinceName + "</option>");
                    });
                }
            });
        });
    </script>
</head>
<body>
    <div class="easyui-panel" title="查询条件" iconcls="icon-search" collapsible="true">
        <div class="search-condition">
            <div>
                VIP卡号：<input id="txtVipNo" type="text" />
                姓名：<input id="txtVipName" type="text" />
                证件号码：<input id="txtVipZjno" type="text" />
                发卡地区：<input id="txtVipDq" type="text" />
            </div>
            <div>
                发卡日期：<input id="txtStartVipDat" type="text" readonly="readonly" />至<input id="txtEndVipDat"
                    type="text" readonly="readonly" />
                有效期：<input id="txtStartVipJsrq" type="text" readonly="readonly" />至<input id="txtEndVipJsrq"
                    type="text" readonly="readonly" />
                <a id="search" class="easyui-linkbutton" plain="true" iconcls="icon-search">查询</a>
                <a id="reset" class="easyui-linkbutton" plain="true" iconcls="icon-empty">清空</a>
            </div>
        </div>
    </div>
    <div id="viplist" style="margin-top: 5px; clear: both;">
    </div>
    <div id="dlgEditVIP" title="编辑VIP资料" iconcls="icon-add-blue">
        <form id="frmVIP" method="post">
        <table class="table-dialog">
            <tr>
                <td>
                    VIP编号：
                </td>
                <td>
                    <input id="VipNo" name="VipNo" type="text" />
                    <span class="required">*</span>
                </td>
                <td>
                    姓名：
                </td>
                <td>
                    <input id="VipName" name="VipName" type="text" />
                    <span class="required">*</span>
                </td>
                <td>
                    电话：
                </td>
                <td>
                    <input id="VipTel" name="VipTel" type="text" />
                </td>
            </tr>
            <tr>
                <td>
                    QQ：
                </td>
                <td>
                    <input id="VipQq" name="VipQq" type="text" />
                </td>
                <td>
                    邮箱：
                </td>
                <td>
                    <input id="VipEmail" name="VipEmail" type="text" />
                </td>
                <td>
                    手机：
                </td>
                <td>
                    <input id="VipPho" name="VipPho" type="text" />
                </td>
            </tr>
            <tr>
                <td>
                    所属省份：
                </td>
                <td>
                    <select id="VipPro" name="VipPro">
                    </select>
                </td>
                <td>
                    邮政编码：
                </td>
                <td>
                    <input id="VipPost" name="VipPost" type="text" />
                </td>
                <td>
                    特别纪念日：
                </td>
                <td>
                    <input id="VipTbjnr" name="VipTbjnr" type="text" />
                </td>
            </tr>
            <tr>
                <td>
                    地址：
                </td>
                <td colspan="5">
                    <input id="VipAdd" name="VipAdd" type="text" style="width: 550px" />
                </td>
            </tr>
            <tr>
                <td>
                    生日：
                </td>
                <td>
                    <input id="VipGlsr" name="VipGlsr" type="text" />
                </td>
                <td>
                    性别：
                </td>
                <td>
                    <select id="VipSex" name="VipSex">
                        <option>男</option>
                        <option>女</option>
                    </select>
                </td>
                <td>
                    婚姻状况：
                </td>
                <td>
                    <select id="VipHf" name="VipHf">
                        <option>已婚</option>
                        <option>未婚</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    学历：
                </td>
                <td>
                    <input id="VipXl" name="VipXl" type="text" />
                </td>
                <td>
                    职业：
                </td>
                <td>
                    <input id="VipZy" name="VipZy" type="text" />
                </td>
                <td>
                    民族：
                </td>
                <td>
                    <input id="VipMz" name="VipMz" type="text" />
                </td>
            </tr>
            <tr>
                <td>
                    证件类别：
                </td>
                <td>
                    <input id="VipZjlb" name="VipZjlb" type="text" />
                    <span class="required">*</span>
                </td>
                <td>
                    证件号码：
                </td>
                <td>
                    <input id="VipZjno" name="VipZjno" type="text" />
                    <span class="required">*</span>
                </td>
                <td>
                    发卡日期：
                </td>
                <td>
                    <input id="VipDat" name="VipDat" type="text" readonly="readonly" class="readonly" />
                </td>
            </tr>
            <tr>
                <td>
                    发卡地区：
                </td>
                <td>
                    <input id="VipDq" name="VipDq" type="text" />
                    <span class="required">*</span>
                </td>
                <td>
                    有效日期：
                </td>
                <td colspan="3">
                    <input id="VipJsrq" name="VipJsrq" type="text" />
                    <span class="required">*</span>
                </td>
            </tr>
        </table>
        </form>
    </div>
</body>
</html>
